package com.biz.primus.ms.auth.dao.repository;

import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.ms.auth.dao.po.Role;
import com.biz.primus.ms.base.jpa.repository.CommonJpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Repository
public interface RoleRepository extends CommonJpaRepository<Role, Long>, RoleDao, JpaSpecificationExecutor<Role> {

    @Transactional
    @Modifying
    @Query("UPDATE Role role SET role.status=:status WHERE role.id=:id")
    void updateStatus(@Param("id") Long id, @Param("status") CommonStatus statusEnum);

    List<Role> findByStatus(CommonStatus status);

    Role findByNameAndStatus(String name, CommonStatus enable);

}
